/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.helper;


/**
 * Assert Helper
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: AssertHelper.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public class AssertHelper {
    /**
     * hasText
     *
     * @param text
     * @param message
     */
    public static void hasText(String text, String message) {
        if (!AssertHelper.hasText(text)) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * hasText
     *
     * @param str
     * @return
     */
    private static boolean hasText(String str) {
        return hasText((CharSequence) str);
    }

    /**
     * hasText
     *
     * @param str
     * @return
     */
    private static boolean hasText(CharSequence str) {
        if (!hasLength(str)) {
            return false;
        }
        int strLen = str.length();
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return true;
            }
        }
        return false;
    }

    /**
     * hasLength
     *
     * @param str
     * @return
     */
    private static boolean hasLength(CharSequence str) {
        return (str != null && str.length() > 0);
    }

    /**
     * 不为空
     *
     * @param object
     * @param message
     */
    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * 为空
     *
     * @param object
     * @param message
     */
    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new IllegalArgumentException(message);
        }
    }
}
